package com.dlg.exchange.gateway.container;


import com.dlg.common.order.OrderCmd;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
@Service
public class OrderCmdContainer {

    private final BlockingQueue<OrderCmd> queue = new LinkedBlockingDeque<>();

    public boolean cache(OrderCmd cmd){
        return queue.offer(cmd);
    }

    public int size(){
        return queue.size();
    }

    public List<OrderCmd> getAll(){
        List<OrderCmd> msgList = Lists.newArrayList();
        int count  = queue.drainTo(msgList);
        if(count == 0){
            return null;
        }else {
            return msgList;
        }
    }

}
